﻿using ETHotfix;
using ETModel;
using System;
using UnityEngine;

namespace DemoPathfinding.Hotfix.Handlers {
    public static class MessageHelper {
        public static void Broadcast(IActorMessage message,long? excludePlayerId = null) {
            var players = Game.Scene.GetComponent<MapPlayersComponent>().GetAll();
            var actorMsgSenderComp = Game.Scene.GetComponent<ActorMessageSenderComponent>();
            foreach (var player in players) {
                if (player.IsDisconnect || (excludePlayerId.HasValue && excludePlayerId.Value == player.Id)) {
                    continue;
                }

                var actorMsgSender = actorMsgSenderComp.Get(player.GateSessionActorId);
                actorMsgSender.Send(message);
            }
        }

    }
}
